<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>编辑考勤</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f8f9fa;
            padding: 20px;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
        }

        h1 {
            text-align: center;
            color: #007bff;
            margin-bottom: 30px;
        }

        .form-container {
            background-color: white;
            padding: 30px;
            border-radius: 5px;
            box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
            width: 400px;
        }

        label {
            display: block;
            margin-bottom: 10px;
            font-weight: bold;
            color: #333;
        }

        input[type="text"],
        input[type="date"],
        input[type="time"] {
            width: 100%;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 3px;
            margin-bottom: 20px;
        }

        button {
            background-color: #007bff;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 3px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        button:hover {
            background-color: #0056b3;
        }
    </style>
</head>

<body>
<h1>编辑考勤</h1>

<div class="form-container">
    <input type="hidden" id="attendanceId">
    <label for="teacherid">教师编号：</label>
    <input type="text" id="teacherid" required>
    <label for="attendanceDate">日期：</label>
    <input type="date" id="attendanceDate" required>
    <label for="clockInTime">上班时间：</label>
    <input type="time" id="clockInTime" required>
    <label for="clockOutTime">下班时间：</label>
    <input type="time" id="clockOutTime" required>
    <label for="attendanceStatus">考勤状态：</label>
    <input type="text" id="attendanceStatus" required>
    <label for="remarks">备注：</label>
    <input type="text" d="remarks">
    <button onclick="updateAttendance()">更新</button>
</div>

<script>
    $(document).ready(function () {
        const id = new URLSearchParams(window.location.search).get('id');
        if (id) {
            $.get(`/attendance/${id}`, function (data) {
                $('#attendanceId').val(data.attendanceId);
                $('#teacherid').val(data.teacherid);
                $('#attendanceDate').val(data.attendanceDate);
                $('#clockInTime').val(data.clockInTime);
                $('#clockOutTime').val(data.clockOutTime);
                $('#attendanceStatus').val(data.attendanceStatus);
                $('#remarks').val(data.remarks);
            });
        }
    });

    function updateAttendance() {
        const attendance = getFormData();
        $.ajax({
            url: '/attendance/update',
            method: 'PUT',
            data: JSON.stringify(attendance),
            success: function () {
                alert('考勤信息更新成功！');
                window.location.href = 'attendance.html';
            }
        });
    }

    function getFormData() {
        return {
            attendanceId: $('#attendanceId').val(),
            teacherid: $('#teacherid').val(),
            attendanceDate: $('#attendanceDate').val(),
            clockInTime: $('#clockInTime').val(),
            clockOutTime: $('#clockOutTime').val(),
            attendanceStatus: $('#attendanceStatus').val(),
            remarks: $('#remarks').val()
        };
    }
</script>
</body>

</html>